﻿<?xml version="1.0" encoding="utf-8" ?>
<content>
	<mainContent>
		<![CDATA[
		<h2>Basic Configuration <span>and Defining Rules.</span></h2>
		<p>To integrate into your website, you first need to add the following into your web.config:</p>
		<pre class="csharpcode">
&lt;configSections&gt;
  &lt;sectionGroup name=<span class="str">"dnAide"</span>&gt;
    &lt;section name=<span class="str">"web"</span> type=<span class="str">"DNAide.Configuration.WebConfig"</span> allowDefinition=<span class="str">"MachineToApplication"</span> restartOnExternalChanges=<span class="str">"true"</span>/&gt;
  &lt;/sectionGroup&gt;
&lt;/configSections&gt;


&lt;dnAide&gt;
  &lt;web&gt;
    &lt;urlRewriter&gt;
      &lt;rules/&gt;
    &lt;/urlRewriter&gt;
  web&gt;
&lt;/dnAide&gt;


&lt;system.web&gt;
  &lt;httpModules&gt;
    &lt;add type=<span class="str">"DNAide.Web.UrlRewriter"</span> name=<span class="str">"UrlRewriter"</span>/&gt;
  &lt;/httpModules&gt;
&lt;/system.web&gt;</pre>
		
		<p>All of this may look a bit weighty but it is simply setting up the DNAide config section and adding UrlAide as a HttpModule.</p>
			
		<h3>Defining Rules.</h3>
		<p>All rules are defined in the DNAide config section in your Web.Config e.g.</p>
			<pre class="csharpcode">
&lt;dnAide&gt;
    &lt;web&gt;
        &lt;urlRewriter&gt;
            &lt;rules&gt;
                
                &lt;add 
                    id=<span class="str">"rule-1"</span> 
                    matchExpression=<span class="str">"~/news.aspx"</span> 
                    destination=<span class="str">"~/news/index.htm"</span> 
                    ruleType=<span class="str">"redirect"</span> 
                    redirectStatusCode=<span class="str">"301"</span> 
                /&gt;
 
                &lt;add 
                    id=<span class="str">"rule-2"</span> 
                    matchExpression=<span class="str">"~/products/(.*)/(.*).aspx"</span> 
                    destination=<span class="str">"~/_Templates/WebForms/ViewProduct.aspx?id=$2"</span> 
                /&gt;

            &lt;/rules&gt;
        &lt;/urlRewriter&gt;
    &lt;/web&gt;
&lt;/dnAide&gt;</pre>
			
			<p>The first rule matches "http://www.mywebsite.com/news.aspx" and redirects to "http://www.mywebsite.com/news/index.htm". The rule also adds a 301 status code meaning that "all future requests should be directed to the given URI".</p>
				 
			<p>The second rule would match "http://www.mywebsite.com/products/1/my-product.aspx" and would rewrite the request to "http://www.mywebsite.com/_Templates/WebForms/ViewProduct.aspx?id=1.</p>
			
			
			<h3>Rule Options.</h3>
			
			<p>Each rule has the following configurable options:</p>
			<ul>
				<li><strong>matchExpression:</strong> Regular expression used against requested Url</li>
				<li><strong>destination:</strong> Where the request should be redirected to</li>
				<li><strong>destinationType:</strong> "UrlPattern, SiteMapNodeKey, Ignore". Default "UrlPattern". "SiteMapNodeKey" will rewrite the request if a pattern is matched to a node in the sitemap</li>
				<li><strong>ruleType:</strong> "Rewrite, Redirect". Default "Rewrite"</li>
				<li><strong>redirectStatusCode:</strong> i.e. what is added to the response header e.g. 301, 404 etc. Default = "301"</li>
			</ul>
				 
			<h3>Additional UrlRewriter Rules</h3>
			<p>In addition to rule specific options, the rewriter has the following common options:</p>
			<ul>
				<li><strong>firesOnEvent:</strong> "BeginRequest, AuthorizeRequest, AuthenticateRequest, None". Default "BeginRequest"</li>
				<li><strong>virtualUrlsOnly:</strong> Rewriting will only occur for virtual file requests, i.e. the file does not physically exist on the server. Default "True"</li>
				<li><strong>applicableFileExtensions:</strong> Valid file extensions for rewriting to occur. Default ".asp,.htm". To allow all, use ".*"</li>
				<li><strong>defaultPage:</strong> If the requested Url does not include a file name i.e. "http://www.mywebsite.com/news" and you have enabled IIS wildcard mappping, this page will be appended by the rewriter to the url e.g. "http://www.mywebsite.com/news/index.aspx"</li>
			</ul>
			
			<pre class="csharpcode">
&lt;dnAide&gt;
    &lt;web&gt;
        &lt;urlRewriter firesOnEvent=<span class="str">"AuthorizeRequest"</span> /&gt;
    &lt;/web&gt;
&lt;/dnAide&gt;</pre>
		]]>
	</mainContent>

	<secondaryContent>
		<![CDATA[
		]]>
	</secondaryContent>
</content>